<%@page contentType="text/html; charset=utf-8"%>
<%@ include file="../inc/TagLibs.jsp"%>
<c:if test="${type=='CLIENT'}"><c:set var="pageTopTitle" value="客户" /></c:if>
<c:if test="${type=='PROVIDER'}"><c:set var="pageTopTitle" value="供应商" /></c:if>
<c:if test="${type=='COOPERATOR'}"><c:set var="pageTopTitle" value="外协商" /></c:if>
<c:set var="pageTitle" value="选择${pageTopTitle}" />
<%@ include file="../inc/Title.jsp"%>
<head>
<link href="/css/base.css" rel="stylesheet" type="text/css">
<link href="/css/Query.css" rel="stylesheet" type="text/css">
<script src="/js/QueryList.js"></script>
<script src="/js/popup_ext.js"></script>
<script src="/js/jquery.js"></script>
<script language="javascript">
	function doNew(){
		var url="/base/EstablishmentNew.ihtm?alert_type=NONE&type=${type}";
		ShowIframe("${pageTopTitle}",url,980,500,"doSelectNew()",900,500);
	}
	function doSelectNew(){
		if(popRetVal!=null){
			document.getElementById("LoadProcess").style.top=getTopPos(document.getElementById("search_key"))+50+"px";
			document.getElementById("LoadProcess").style.left=getleftPos(document.getElementById("search_key"))+100+"px";
			$("#LoadProcess").show();
			$.post("/base/GetEstInfo.ihtm",{est_id:popRetVal},function(data,status){
				parseSelectNewData(data,status);
			});
		}
	}
	function parseSelectNewData(data,status){
		$("#LoadProcess").hide();
		if(status=="success"){
			var obj=$.parseJSON(data);
			if(obj.status=="ERROR"){
				ShowAlert('提示框',obj.errMsg,200,100);
			}else{
				var arr=new Array();
				arr[0]=obj.id;
				arr[1]=obj.estName;
				arr[2]=obj.mngId;
				arr[3]=obj.mngName;
				arr[4]=obj.canMng;
				arr[5]=obj.phon;
				arr[6]=obj.addr;
				arr[7]=obj.lm;
				arr[8]=obj.lmPhon;
				arr[9]=obj.baName;
				arr[10]=obj.baAccCode;
				arr[11]=obj.baAccName;
				parent.popRetVal=arr;
				parent.ClosePop();
			}
		}else{
			ShowAlert('提示框','系统错误：'+status,200,100);
		}
	}
	function refreshWin(){
		window.location=window.location;
	}
	function doSearch(){
		var type="${type}";
		var searchKey=encodeURIComponent(document.getElementById("search_key").value.trim());
		var typeId="";
		if(document.getElementById("type_id")!==null){
			typeId=document.getElementById("type_id").value;
		}
		var levelId="";
		if(document.getElementById("level_id")!=null){
			levelId=document.getElementById("level_id").value;
		}
		var areaId=document.getElementById("area_id").value;
		var tsId="${tsId}";
		var showAll="${showAll}";
		var orderType="${orderType}";
		window.location="/base/EstablishmentListForSelect.ihtm?type="+type+"&type_id="+typeId+"&level_id="+levelId+"&area_id="+areaId+"&ts_id="+tsId+"&show_all="+showAll+"&search_key="+searchKey+"&order_type="+orderType;
	}
	function doGo(pageIndex){
		var searchKey=encodeURIComponent("${searchKey}");
		var type="${type}";
		var typeId="${typeId}";
		var levelId="${levelId}";
		var areaId="${areaId}";
		var tsId="${tsId}";
		var showAll="${showAll}";
		var orderType="${orderType}";
		window.location="/base/EstablishmentListForSelect.ihtm?type="+type+"&type_id="+typeId+"&level_id="+levelId+"&area_id="+areaId+"&ts_id="+tsId+"&show_all="+showAll+"&search_key="+searchKey+"&order_type="+orderType+"&current_page="+pageIndex;
	}
	function doJump(pageIndex){
		if(window.event.keyCode==13){
			doGo(pageIndex);
		}
	}

	function doSelect(index){
		var ob_arr = document.getElementsByName("query_checkbox");
		var arr=new Array();
		if ( ob_arr.length>=index ){
			arr[0]=ob_arr[index-1].value;
			arr[1]=ob_arr[index-1].getAttribute("est_name");
			arr[2]=ob_arr[index-1].getAttribute("manager_id");
			arr[3]=ob_arr[index-1].getAttribute("manager_name");
			arr[4]=ob_arr[index-1].getAttribute("can_manage");
			arr[5]=ob_arr[index-1].getAttribute("phone");
			arr[6]=ob_arr[index-1].getAttribute("addr");
			arr[7]=ob_arr[index-1].getAttribute("linkman");
			arr[8]=ob_arr[index-1].getAttribute("lm_phone");
			
			arr[9]=ob_arr[index-1].getAttribute("ba_name");
			arr[10]=ob_arr[index-1].getAttribute("ba_acc_code");
			arr[11]=ob_arr[index-1].getAttribute("ba_acc_name");
			parent.popRetVal=arr;
			parent.ClosePop();
		}
	}
	function doCancel(){
		parent.ClosePop();
	}
	function DoubleClick(it){
		var ob_arr = document.getElementsByName("query_checkbox");
		var arr=new Array();
		if(ob_arr.length>=it.getAttribute("index")){
			
			arr[0]=ob_arr[it.getAttribute("index")-1].value;
			arr[1]=ob_arr[it.getAttribute("index")-1].getAttribute("est_name");
			arr[2]=ob_arr[it.getAttribute("index")-1].getAttribute("manager_id");
			arr[3]=ob_arr[it.getAttribute("index")-1].getAttribute("manager_name");
			arr[4]=ob_arr[it.getAttribute("index")-1].getAttribute("can_manage");
			arr[5]=ob_arr[it.getAttribute("index")-1].getAttribute("phone");
			arr[6]=ob_arr[it.getAttribute("index")-1].getAttribute("addr");
			arr[7]=ob_arr[it.getAttribute("index")-1].getAttribute("linkman");
			arr[8]=ob_arr[it.getAttribute("index")-1].getAttribute("lm_phone");
			
			arr[9]=ob_arr[it.getAttribute("index")-1].getAttribute("ba_name");
			arr[10]=ob_arr[it.getAttribute("index")-1].getAttribute("ba_acc_code");
			arr[11]=ob_arr[it.getAttribute("index")-1].getAttribute("ba_acc_name");
			parent.popRetVal=arr;
			parent.ClosePop();
		}
	}
	function doInit(){
		Window_Onload();
		resizePopwin();
		document.getElementById("search_key").focus();
	}
	function checkSearchKey(){
		if(window.event.keyCode==13){
			doSearch();
		}
	}
</script>
</head>
<body oncontextmenu="return false" onload="doInit();" class="sheet">
<div class="sheet-main" style="width:856px;">
  <div class="sheet-top">
    <div class="content">
      <h2>选择${pageTopTitle}</h2>
      <p>鼠标双击选中记录，支持以${pageTopTitle}名称、${pageTopTitle}拼音字头、联系人名称进行模糊查询</p>
    </div>
  </div>
  <div class="sheet-list">
    <div class="search-business">
      <div class="content">
        <table width="748">
          <tbody>
            <tr>
              <td  align="right">
		            <input type="text" class="TextBox" id="search_key" name="search_key" onKeyUp="checkSearchKey();" style="width:100px" value="${searchKey}" title="以${pageTopTitle}名称、${pageTopTitle}拼音字头、联系人名称进行模糊查询">
					<c:if test="${type=='CLIENT'}">
					<select id='type_id' name='type_id'>
						<option value="0">==全部类别==</option>
						<c:forEach var="item" items="${estTypeList}">
						<option value="${item.id}" <c:if test="${typeId==item.id}">selected</c:if>>${item.typeName}</option>
						</c:forEach>
		  			</select>
		  			<select id='level_id' name='level_id'>
						<option value="0">==全部等级==</option>
						<c:forEach var="item" items="${estLevelList}">
						<option value="${item.id}" <c:if test="${levelId==item.id}">selected</c:if>>${item.levelName}</option>
						</c:forEach>
		  			</select>
		  			</c:if>
		  			<select name="area_id" id="area_id" style="width:140px">
						<option value="0">==全部地区==</option>
						<commonTag:createSelectTree list="${areaList}" emptyOption="0" justEnabled="1" defaultValue="${areaId}" />
					</select>
					<input type="button" class="buttom search-but" value=" 查 询" onClick="doSearch();" title="以${pageTopTitle}名称、${pageTopTitle}、联系人名称拼音字头进行模糊查询">
					
					<c:set var="newFlag" value="0" />
					<c:if test="${type=='CLIENT'}">
						<c:if test="${currentUser.user.userType==1 || fn:indexOf(currentUser.privs,';BUSI_CLIE;')!=-1}">
							<c:set var="newFlag" value="1" />
						</c:if>
					</c:if>
					<c:if test="${type=='PROVIDER'}">
						<c:if test="${currentUser.user.userType==1 || fn:indexOf(currentUser.privs,';PURC_PROV;')!=-1}">
							<c:set var="newFlag" value="1" />
						</c:if>
					</c:if>
					<c:if test="${type=='COOPERATOR'}">
						<c:if test="${currentUser.user.userType==1 || fn:indexOf(currentUser.privs,';COOP_COOP;')!=-1}">
							<c:set var="newFlag" value="1" />
						</c:if>
					</c:if>
					<c:if test="${newFlag=='1'}">
						<input type="button" class="buttom search-add" value=" 新 增" onClick="doNew();" title="添加一个新${pageTopTitle}">
					</c:if>
			</td>
            </tr>    
           </tbody>      
        </table>
      </div>
	  <%@include file="../inc/AlertMsg.jsp"%>
      <div class="table-list">
        <table width="100%">      
			<tr >
				<th width="14"></th>
				<th width="12%">编号</th>
				<th width="26%">名称</th>
				<th width="12%">联系人</th>
				<th width="28%">备注</th>
				<th width="12%">经办人</th>
				<th width="10%">操作</th>
			</tr>
			<c:forEach var="item" items="${qr.list}" varStatus="i">
				<c:if test="${(i.index mod 2)==0}"><c:set var="trClass" value="query_list_data_tr1" /></c:if>
				<c:if test="${(i.index mod 2)!=0}"><c:set var="trClass" value="query_list_data_tr2" /></c:if>
				<c:if test="${item.establishment.bankName1!=null && item.establishment.bankName1!=''}"><c:set var="baName" value="${item.establishment.bankName1}" /><c:set var="baAccCode" value="${item.establishment.bankAccCode1}" /><c:set var="baAccName" value="${item.establishment.bankAccName1}" /></c:if>
				<c:if test="${item.establishment.bankName1==null || item.establishment.bankName1==''}"><c:set var="baName" value="${item.establishment.bankName2}" /><c:set var="baAccCode" value="${item.establishment.bankAccCode2}" /><c:set var="baAccName" value="${item.establishment.bankAccName2}" /></c:if>
				<tr class="${trClass}" index="${i.index+1}" style='cursor:pointer;' ondblclick='javascript:DoubleClick(this)' onClick='javascript:ClickCheck(this)' onmouseout='javascript:mouseout(this)' onmouseover='javascript:mouseover(this)'>
					<td><input type="radio" name='query_checkbox' value="${item.establishment.id}" est_name="${item.establishment.estName}" manager_id="${item.establishment.managerId}" manager_name="${item.establishment.managerName}" can_manage="${item.canManage}" phone="${item.establishment.phone}" addr="<c:out value="${item.establishment.address}" />" linkman="${item.establishment.linkman}" lm_phone="${item.establishment.linkmanPhone}" ba_name="${baName}" ba_acc_code="${baAccCode}" ba_acc_name="${baAccName}"></td>
					<td>${item.establishment.estCode}</td>
					<td>${item.establishment.estName}</td>
					<td>${item.establishment.linkman}</td>
					<td>${item.establishment.mark}</td>
					<td>${item.establishment.managerName}</td>
					<td>
						<a href="javascript:doSelect('${i.index+1}');">选择</a>
					</td>
				</tr>
			</c:forEach>
		</table>
		<%@include file="../inc/Pages.jsp"%>
      </div>
    </div>
  </div>
</div>
<%@ include file="../inc/LoadingDiv.jsp"%>
</body>
</html>